// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_autostart::ManagerExt;
#[tauri::command]
fn greet(name: &str) -> String {
    format!("Hello, {}! You've been greeted from Rust!", name)
}
pub mod clipboard;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_clipboard_manager::init())
        .plugin(tauri_plugin_global_shortcut::Builder::new().build())
        .plugin(tauri_plugin_autostart::init(
            MacosLauncher::LaunchAgent,
            Some(vec!["--flag1", "--flag2"]),
        )).setup(|app| {
            let autostart_manager = app.autolaunch();
            let _ = autostart_manager.enable();
            println!(
                "registered for autostart? {}",
                autostart_manager.is_enabled().unwrap()
            );
            // let _ = autostart_manager.disable();
            Ok(())
        })
        // .setup(|app| {
        //     #[cfg(desktop)]
        //     {
        //         use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut};
        //         let ctrl_n_shortcut = Shortcut::new(Some(Modifiers::CONTROL), Code::KeyN);
        //         app.handle().plugin(
        //             tauri_plugin_global_shortcut::Builder::new().with_handler(move |_app, shortcut, shortcut_event| {
        //                 println!("{:?}", shortcut);
        //                 if shortcut == &ctrl_n_shortcut {
        //                     println!("Ctrl-N Detected!");
        //                 }
        //             })
        //             .build(),
        //         )?;

        //         app.global_shortcut().register(ctrl_n_shortcut)?;
        //     }
        //     Ok(())
        // })
        .plugin(tauri_plugin_opener::init())
        .invoke_handler(tauri::generate_handler![greet])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
